package org.xiaojinlong.exam;

import java.util.Scanner;

/**
 * @author Jin Long
 * 2015/9/29
 */
public class A3601 {
    private static class UF {
        private int[] id;
        private int[] sz;

        public UF(int n) {
            id = new int[n + 1];
            sz = new int[n + 1];
            for (int i = 1; i < id.length; i++) {
                id[i] = i;
                sz[i] = 1;
            }
        }

        private int root(int i) {
            while (i != id[i]) {
                id[i] = id[id[i]]; // 路径压缩
                i = id[i];
            }
            return i;
        }

        public boolean connected(int p, int q) {
            return root(p) == root(q);
        }

        public void union(int p, int q) {
            int i = root(p);
            int j = root(q);
            if (i == j) return;
            if (sz[i] < sz[j]) {
                id[i] = j;
                sz[j] += sz[i];
            } else {
                id[j] = i;
                sz[i] += sz[j];
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n, m;
        while ( (n = scanner.nextInt()) != 0 && (m = scanner.nextInt()) != 0) {
            UF uf = new UF(n);
            for (int i = 0; i < m; i++) {
                int a = scanner.nextInt();
                int b = scanner.nextInt();
                uf.union(a, b);
            }

            int count = 0;
            for (int i = 2; i <= n; i++)
                if (uf.connected(1, i))
                    count++;

            System.out.println(count);
        }
    }
}